#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<string> getLongestSubsequence(vector<string>& words, vector<int>& groups) {
        bool prev_flag = false;
        vector<string> res;
        for (int i = 0; i < words.size(); i++)
        {
            if (res.empty())
            {
                res.push_back(words[i]);
                prev_flag = groups[i];
            }
            else
            {
                if (groups[i] == prev_flag)
                {
                    string tmp = res.back();
                    tmp = tmp.size() >= words[i].size() ? tmp : words[i];
                }
                else
                {
                    res.push_back(words[i]);
                    prev_flag = !prev_flag;
                }
            }
        }
        return res;
    }
};